开发者

JSF2.0 Composite Component ID generation

I'm in the process of creating a new Web Application using JSF2.0 on Weblogic 11g. I'm using JSF Ajax for form submission. I'm quite new to JSF so still learning the ropes. The main page has 3 forms each on a jQuery tab. The original code had a lot of duplicate Input Fields like userName and password etc (id prepended with the form id i.e. myform1:userName). I decided it would be a good idea to use Composite Components for the duplicated fields. Here is my Conponent code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.or开发者_开发知识库g/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:composite="http://java.sun.com/jsf/composite"
  xmlns:h="http://java.sun.com/jsf/html">

<composite:interface>
    <composite:attribute name="value" required="true"/>
</composite:interface>

<composite:implementation>

<label for="#{cc.id}">User Name</label>
<h:inputText
        id="#{cc.id}"
        size="15"
        value="#{cc.attrs.value}"
        required="true"
        label="User Name">
</h:inputText>
</composite:implementation>

</html>

And here is the call to the Component in the xhtml:

<p>
    <cc:userName id="userName" value="#{soapTestingBackingBean.userName}"/>
</p>

The problem now is that all my ids have an added element so have become myForm1:userName:userName. Although this isn't a show stopper it does mean that my javascript now has to reference the long ids and is also the same in my Ajax calls (I generally execute @form but render specific elements). I'm trying to make the code as readable and maintainable as possible. So would appreciate it if anyone knew if there were an elegant work around for this or maybe some magic attribute I missed to turn it off. I did experiment with the forceID attribute from the tomahawk library but this just caused additional problems on my Ajax calls. Thanks.


some java script libraries jQuery are having problem with the new format for jsf 2.0 ids form:elementId - so instead of using

$(function() {
    $( "#datepicker" ).datepicker();
});

I had to use

$(function() {
    $(document.getElementById('addform:datepicker')).datepicker();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜