java 隐藏表单,java – 为什么渲染器添加一个带有表单ID的隐藏字段作为名称和值...

我正在阅读JSF实现< h:form>渲染.令我惊讶的是,我看到(在Mojarra,MyFaces Tomahawk中),他们在encodeBegin()方法上添加了一个隐藏的输入字段.

以下是Mojarra中FormRenderer的示例代码:

@Override

public void encodeBegin(FacesContext context, UIComponent component)

throws IOException {

rendererParamsNotNull(context, component);

if (!shouldEncode(component)) {

return;

}

ResponseWriter writer = context.getResponseWriter();

assert(writer != null);

String clientId = component.getClientId(context);

// since method and action are rendered here they are not added

// to the pass through attributes in Util class.

writer.write('\n');

writer.startElement("form", component);

writer.writeAttribute("id", clientId, "clientId");

writer.writeAttribute("name", clientId, "name");

writer.writeAttribute("method", "post", null);

writer.writeAttribute("action", getActionStr(context), null);

String styleClass =

(String) component.getAttributes().get("styleClass");

if (styleClass != null) {

writer.writeAttribute("class", styleClass, "styleClass");

}

String acceptcharset = (String)

component.getAttributes().get("acceptcharset");

if (acceptcharset != null) {

writer.writeAttribute("accept-charset", acceptcharset,

"acceptcharset");

}

RenderKitUtils.renderPassThruAttributes(context,

writer,

component,

ATTRIBUTES);

writer.writeText("\n", component, null);

// this hidden field will be checked in the decode method to

// determine if this form has been submitted.

writer.startElement("input", component);

writer.writeAttribute("type", "hidden", "type");

writer.writeAttribute("name", clientId,

"clientId");

writer.writeAttribute("value", clientId, "value");

writer.endElement("input");

writer.write('\n');

// Write out special hhidden field for partial submits

String viewId = context.getViewRoot().getViewId();

String actionURL =

context.getApplication().getViewHandler().getActionURL(context, viewId);

ExternalContext externalContext = context.getExternalContext();

String encodedActionURL = externalContext.encodeActionURL(actionURL);

String encodedPartialActionURL = externalContext.encodePartialActionURL(actionURL);

if (encodedPartialActionURL != null) {

if (!encodedPartialActionURL.equals(encodedActionURL)) {

writer.startElement("input", component);

writer.writeAttribute("type", "hidden", "type");

writer.writeAttribute("name", "javax.faces.encodedURL", null);

writer.writeAttribute("value", encodedPartialActionURL, "value");

writer.endElement("input");

writer.write('\n');

}

}

if (!writeStateAtEnd) {

context.getApplication().getViewHandler().writeState(context);

writer.write('\n');

}

}

我的问题:

>为什么有一个隐藏的输入字段被赋予id component.getClientId(context),即一个UIForm组件?隐藏领域的目的是什么?

>在Mojarra中,您无法在< h:form>上指定自己的id属性.但你可以在MyFaces上.在每种情况下,JSF如何处理UIForm(例如,当MyFaces有明确提供的ID时)?

> Mojarra form enctype默认为application / x-www-form-urlencoded.它可以支持multipart / form-data或text / plain吗?

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值