Struts2 checkbox tree structure? - html

I need to make a tree structure with my JSP Code.
In the data taken from a database, there's a parent field which should identify the child nodes; I use the
<s:iterator value="Activities">
<s:property value="idActivity" />
<s:property value="name" />
<s:property value="parent" />
</s:iterator>
Any ideas? I tried to use dynatree Library from GoogleCode but it didn't work.

If by tree structure you mean a tree-like indentation, just use <ul> and <li>.
Also pay attention to the list you're iterating, that should start with a lowercase letter:
<ul>
<s:iterator value="activities">
<li>
<s:property value="idActivity" />
<s:property value="name" />
<s:property value="parent" />
</li>
</s:iterator>
</ul>
BTW the question is very unclear, and it doesn't involve any checkbox. Try to be more specific next time (or this one, if this answer is not the one you're looking for)

Related

How to set <s:property> value to Struts 2 Checkbox in Iterator and give all the selected check boxes value in Action List

I Want to get selected checkbox value from checkbox Key property on Action Class as List.
My code look like this
<s:form action="SearchEmail">
<s:iterator value="ls">
<s:checkbox name="chk" key="number" />
</s:iterator>
<s:submit value="Go"/>
</s:form>
<s:iterator value="ls" status="stat">
<s:checkbox name="chk[%{#stat.index}]" key="number" />
<%-- <s:property value="number"/> --%>
</s:iterator>
The output is:
Value of CheckBox:{0=true, 1=false, 2=true}
But I need value in String format I don't need Index I need Value of Key property of Checkbox. I want to get the value of Selected Property.
<s:property value="number"/>
<s:checkbox fieldValue="%{number}" name="chk" key="number"> </s:checkbox> <!-- key="number" -->
</s:iterator>
wow it's working with above code.Something Magic. Thank every one to letting me resolve it on my own.
here 'var' attribute makes the sense
<s:iterator value="ls" var="val">
<s:checkbox name="%{val}" id="%{val}" label="%{val}"></s:checkbox>
</s:iterator>

have a dynamic height with error message

Sorry JSF is not my main language
I have a JSF Composite Component named validatedInputTextQuestion. It's essentially a bold label, then a textbox on first line.. next line is a note about said inputText, and below that is where my validation message would show.
<cc:implementation>
<b>#{cc.attrs.questionLabel} : </b>
<h:inputText value="#{cc.attrs.bindingValue}" id="checkSpecs" required="#{cc.attrs.required}" size="15" label="#{cc.attrs.errorLabel}">
<f:validateLength minimum="#{cc.attrs.minLength}" maximum="#{cc.attrs.maxLength}" />
</h:inputText>
<br />
<b>#{cc.attrs.notes}</b>
<br />
<h:message for="checkSpecs" style="color:red" />
<br />
</cc:implementation>
not all instances of this template have a note. but when I test out this page there is a extra break above my error message. Which is to be expected as that is what my template does... What i'd like to know is if there is a dynamic way of having this note attribute take up space if there is data.. I know in Silverlight I could use a grid and set a row definition height of Auto... or use a boolean to visibilty converter, but i can't find the equivalent in JSF. Can someone help point me to a solution for this?

Using JSF h:outputLink to produce a page anchor

Simple question:
How do you create an HTML anchor like
<a id="organization" />
with JSF, e.g.
<h:outputLink ... />
or another JSF link component? Is it possible at all?
You could use <h:link> for that. Its id attribute becomes the <a id> and <a name>.
<h:link id="organization" value="Organization" fragment="organization" />
It generates the following HTML:
<a id="organization" name="organization" href="/currentcontext/currentpage.xhtml#organization">Organization</a>
But just using plain <a> or even <span> or <div> is perfectly legal in JSF/HTML as jump targets.
<span id="organization">Organization</span>
In order to create a link which jumps to that, use <h:link fragment> without id:
<h:link value="Jump to organization" fragment="organization" />
The generated HTML will look like this:
Jump to organization
Why not use
<h:outputLink value="www.yourweb/somePage#anchor" />
or if its on the same page just
<h:outputLink value="#anchor" />
<h:link value="test" outcome="icerik">
<f:param name="id" value="#{icerik.id}" />
</h:link>
This links to icerik.xhtml?id=2 and seems like test

A little help on fieldset and form tags imbrication

I am currently writing a Java EE web-app using JSP's and I have a question regarding HTML tags.
I use fieldsets to properly structurate my forms on the main page and find myself perplexed and was wondering if the following was legal:
<fieldset id="FieldMain">
<form method="post" action="servletA">
<input name="a" type="text" />
<fieldset id="FieldA">
<input name="b" type="text" />
<input name="c" type="text" />
<input name="d" type="submit" value="Go for A" />
</fieldset>
</form>
<form method="post" action="servletB">
<fieldset id="FieldB">
<input name="e" type="text" />
<input name="f" type="text" />
<input name="g" type="submit" value="Go for B" />
</fieldset
</form>
</fieldset>
With the desired result being that when clicking the "Go for A" button it takes into account the field a, b and c (a being outside of the fieldset fieldA but inside the form A tag) while clicking go for B only takes fields e and f.
In other words, if I use field sets, can I have several forms in one single fieldset tag ? And can I have some fields outside of any fieldset tag as long as it is in the form tag ?
Thank you :-)
It's legal, but it's not entended to do this
The FIELDSET element allows authors to group thematically related
controls and labels. Grouping controls makes it easier for users to
understand their purpose while simultaneously facilitating tabbing
navigation for visual user agents and speech navigation for
speech-oriented user agents. The proper use of this element makes
documents more accessible.
Source: http://www.w3.org/TR/html4/interact/forms.html#h-17.10
As far as I remember form past discussions: it's legal according to
the letter of the standard and the DTD also makes it valid where a
block element is valid. Now as to intend, that's harder to determine,
it feels to me to be intended to be used in forms only. I don't know
why it got the far wider scope.
Also note that -despite the CSS standard not stating it should- a
fieldset creates a new stacking context (logical if you think about it
and the default way it's rendered, but not mentioned in the standard
AFAIK).
IMHO extensive use of it outside forms and/or reliance on the new
stacking context are dangerous if you want future proof code.
source: http://www.webmasterworld.com/html/3915579.htm

Can i use struts tags inside the html tags to initialise their attribute?

I am using the following code but haven't tried it yet:
<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />
Is it valid ?
And how can it be acheived more efiiciently ?
You can use server tags to initialize attributes of HTML tags. The code you posted is valid.
This code:
<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />
evaluates to
<input type="checkbox" id="theID" />
assuming that "theID" is what's inside the "idvalue" property of your bean.
Off course this isn't very easy to read even if you use JSTL as VinAy suggested. You will just ed up with something like this:
<input type="checkbox" id="<c:out value="${element.idvalue}" />" />
Again not easy to read if you have an entire JSP full of these.
The Struts html tags come in handy here and generate the input by using a construct like:
<html:text name="element" property="idvalue" />
which, if you have it inside a <html:form> tag can be further simplified to:
<html:text property="idvalue" />
And if all fails, you can always simplify it as much as you want by writing your own JSP custom tags.