Thursday, July 19, 2007

Hashmap examples used in jsp page?

Hi all,

Could anyone please point me to where i can find some examples using
hashmaps in a jsp with struts...
Instead of using a whole bunch of logic equal tags all the time, i need a
way to evaluate a collection, looking for a specific key value, then show or
hide the relevant input boxes on my jsp..
any help...please!!!???

See code sample below. The type in the iterate tag must be as shown, you
will then need to use a bean define to put your 'value' into the page
context and cast it to whatever type you have placed in your HashMap value.



<
logic:iterate id="list" name="gallery" property="artifacts"
type="java.util.Map.Entry">

<
bean:define id="artifact" name="list" property="value"
type="net.itwa.model.artifact.IArtifact"/>
<
bean:write name="artifact" property="description"/>
bean:write name="artifact" property="description">
logic:iterate>

ref

struts

Pass multiple params to html:link

// The only way i found

<bean:define id="param1" name="record" property="id"/>
<bean:define id="param2" name="record" property="language_id" />
<%
java.util.HashMap params = new java.util.HashMap();
params.put("record_id", param1);
params.put("language_id", param2);
pageContext.setAttribute("tempParams", params);
%>
>
Hoja
html:link>

Pass more than one parameter to struts action using html:link tag



<
bean:define id="param1" name="record" property="id"/>
<bean:define id="param2" name="record" property="language_id" />
<%
java.util.HashMap params = new java.util.HashMap();
params.put("record_id", param1);
params.put("language_id", param2);
pageContext.setAttribute("tempParams", params);
%>
>
Hoja
html:link>

struts-config.xml: Global Forward

<global-forwards>
<forward name="error" path="/WEB-INF/jsp/error.jsp"/>
global-forwards>

struts-config.xml: Basic Plugin

<plug-in className="listin.plugins.ListinPlugin">
<set-property property="config_file" value="/WEB-INF/config/Listin.properties"/>
plug-in>

struts-config.xml: Basic Action

  

<action path="/BuscarLDAP" type="listin.actions.BuscarLDAP">
<forward name="success" path="/WEB-INF/jsp/resultados.jsp"/>
action>


ref

Thursday, July 12, 2007

EJB query - subquery

code
ejb-jar.xml=>
select object(o) from UserAccount o
where o.ibuser.userId = ?1 and
o.product.productCode in
(select t.productCode from TransactionRuleProduct t
where t.transactionRuleCode=?2
and (t.isFromAcc =?3 or t.isToAcc=?4))


sql=>
select * from userAccount
where userid ='userxxx'
and productCode
in ( select productode from TransactionRuleProduct
where transactionRuleCode=''
and (isFromAcc =1 or isTooAcc=1)
)


Different of ejbSelect and ejbFind

ejbSelect or find?

i found that the ejbSelectxxx and findxxx method are very similar,the only difference is that it seem like the ejbSelectxxx is not exposed to the client directly,you must wrapper it in a business method,then call the method from client,but i think i can use the findxxx method instead of the ejbSelectxxx method,who can tell me how can i decide when or where i use which method?

reply
First there is no relation between ejbSelect() and ejbFind(). You don't implement ejbFind() methods in CMP entity beans' classes, so you can't call an ejbSelect() method from an ejbFind() method.
Second, in CMP you don't write any persistence logic in your bean class. The container do this. But suppose you want to have a (home) business method. How will look the implementation of this method? No JDBC cals...
Here is the place of ejbSelect() methods. You tell the container how to implement this method just like with ejbFind() methods - with EJB QL. Then from your business method you call the ejbSelect() method. The most powerful thing here is that the result of this invocation can be anything - incl. persistent fields, not only Primary Keys.
Of course if you have relations with other entity beans the result will be an EJBObject ( or a collection ).

Finder and select methods use EJB QL queries to return objects and state information of entity beans using container-managed persistence.

A select method is similar to a finder method in the following ways:

1. A select method can return a local or remote interface (or a collection of interfaces).
2. A select method queries a database.
3. The deployment descriptor specifies an EJB QL query for a select method.
4. The entity bean class does not implement the select method.

However, a select method differs significantly from a finder method:

1. A select method can return a persistent field (or a collection thereof) of a related entity bean. A finder method can return only a local or remote interface (or a collection of interfaces).
2. Because it is not exposed in any of the local or remote interfaces, a select method cannot be invoked by a client. It can be invoked only by the methods implemented within the entity bean class. A select method is usually invoked by either a business or a home method.
3. A select method is defined in the entity bean class. For bean-managed persistence, a finder method is defined in the entity bean class, but for container-managed persistence it is not.


Code

public abstract class AddressBean implements javax.ejb.EntityBean {
...

// Customer home methods.
// These are wrappers of ejbSelect methods

public Collection ejbHomeQueryZipCodes(String state)
throws FinderException {
return ejbSelectZipCodes(state);
}

public Collection ejbHomeQueryAll()
throws FinderException {
return ejbSelectAll();
}

public CustomerLocal ejbHomeQueryCustomer(AddressLocal addr)
throws FinderException {
return ejbSelectCustomer(addr);
}
...
}




ref1
ref2
ref3

Tuesday, July 10, 2007

Jasper Text Field Expression

How to do Text Field Expression in Jasper when I have more than one condition checking to output the textField?
Example...
I might have applicationResour
ceKey "key1","key2","key3", and i need to display it as "keyValue1","keyValue2","keyValue3"















Code

($F{key}).equals("key1") ?
"
keyValue1" :
($F{key}).equals("
key2")?
"
keyValue2":
($F{key}).equals("
key3")?
"
keyValue3":
"-"