How to set ‘autoComplete’ property for html:text component in struts

If you are developing your jsp page using struts then, In few cases you get a requirement that while typing in an input filed it should not show the suggestions that previously entered.

So generally to achieve this we use the property ‘autoComplete=off’ for html input fields. But struts <html:text> doesn’t support this property. So to achieve this feature in struts we have three options.

1) Use normal html input component in the place of  struts html:text component.

<input type="text" value="" autoComplete="off" size="10" maxlength="10" name="Account" />

2) Use <html:text> in the following way that you set ‘autoComplete’ like a css injection. The below method can be used to set properties for the components which are not supported by struts html by default.


<html:text size="10" maxlength="10" property="Account" styleClass="\" autoComplete=\"off" />

3) Create a class extending Form class or Text class and add a custom property in it.

4) You can think of using jQuery also.

 

Advertisements

Hexa to Decimnal conversion in Java

Have you ever tried to print the value of int i=0xbb; ? Do you think it’ll give numeric exception? No it works well and gives you the output of ‘187’. What is this value? It’s a decimal value of ‘bb’.

Well now coming to the point if you give value to integer starts with 0x (zero alphabet x) then jvm will convert the next value after prefix (assumes it as hex value) to decimal value. In the above example the hex value is ‘bb’ and its decimal value is ‘187’ which is then stored into integer. Want to cross check ? You can also do that calculation like below.

eg1: bb -> 11 X 160 + 11 X 161 = (11+176)= 187

eg2: bd -> 13 X 160 + 11 X 161 =(13+176)=189

Confused with Decimal and Hex values? Check below.

Hex             0     1     2     3     4     5     6     7     8     9     A       B     C       D      E       F
Decimal     0     1     2     3     4     5     6     7     8     9     10     11     12     13     14     15

Note: You can see decimal values for the alphabets a to f only. If you give any alphabet other than a to f then it’ll syntax error.

Leave your comments and suggestions in below comment section. Hope you enjoyed the post 🙂
 

Multi Threading Example in Java

Multi threading Can be achieved with the help of ‘Thread Class’ or ‘Runnable Interface’. We have to override the run() method in both the cases and we have to call start() method which automatically calls run method (no need to call run method).

  • If we extend Thread class then we have to call start method with the help of class object.
  • But if you Implement Runnable Interface then we have to explicitly create Thread class object and with that object we have to call start method.
  • If you don’t call start method and simply call run method then it won’t create another thread for you and will be executed by the same thread.
  • If we extend thread class we can not extend another class but if we implement Runnable interface we can extend another class.

Example: In the below example if you  run you can observer that both the threads will be executed in parallel instead one after other as we’ve used the MultiThread concept here with the help of Thread class.

First let’s do an example which extends Thread class to implement MultiThreading. After that we do the same example with the help of Runnable Interface.

package view;

public class MultithreadConcept{
public MultithreadConcept() {
super();
}

public static void main(String[] args) throws InterruptedException {
MultithreadConcept multithreadConcept = new MultithreadConcept();

playSongs ps = new playSongs();
playVideo pv = new playVideo();

ps.start();
pv.start();
}

}
class playSongs extends Thread{
public void run(){
//System.out.println("I am playing song");
for (int i=1; i&lt;=5; i++){
System.out.println("Playing Song:"+i);
try { Thread.sleep(500);} catch (InterruptedException e) {}
}

}
}

class playVideo extends Thread{
public void run(){
// System.out.println("I am playing video");
for (int i=1; i&lt;=5; i++){
System.out.println("Playing Video:"+i);
try { Thread.sleep(500);} catch (InterruptedException e) {}
}
}
}

Output:

Playing Song:1
Playing Video:1
Playing Song:2
Playing Video:2
Playing Song:3
Playing Video:3
Playing Song:4
Playing Video:4
Playing Song:5
Playing Video:5

The same example let’s do it with the help of Runnable Interface.

package view;

public class MultithreadConcept2 {
public MultithreadConcept2() {
super();
}

public static void main(String[] args) {
MultithreadConcept2 multithreadConcept2 = new MultithreadConcept2();

playSongs2 ps = new playSongs2();
playVideo2 pv = new playVideo2();

Thread t1 = new Thread(ps);
Thread t2 = new Thread(pv);
t1.start();
t2.start();
}


}
class playSongs2 implements Runnable{
public void run(){
//System.out.println("I am playing song");
for (int i=1; i<=5; i++){
System.out.println("Playing Song:"+i);
try { Thread.sleep(500);} catch (InterruptedException e) {}
}

}
}

class playVideo2 implements Runnable{
public void run(){
// System.out.println("I am playing video");
for (int i=1; i<=5; i++){
System.out.println("Playing Video:"+i);
try { Thread.sleep(500);} catch (InterruptedException e) {}
}
}
}

Output:

Playing Song:1
Playing Video:1
Playing Song:2
Playing Video:2
Playing Song:3
Playing Video:3
Playing Song:4
Playing Video:4
Playing Song:5
Playing Video:5

 

Applying ViewCriteria dynamically

If you want to Apply ViewCriteria by passing a parameter and then execute the VO query the following methods you can choose based on the requirement.

1) Getting VO from AppModule Instance Programmatically and Applying VC on it: Simply create a java class and register it as a managed bean and then inside the method get the AppModule instance and from which get VO  then apply VC and execute. [This method is not preferable as this might lead to creation of multiple AppModule instances]. shortcut to get the skeleton code is type bc4j and then press Ctrl+Enter inside java method.
Note: You need to close the AppModule instance connection at the end. Generally this will be placed in the finally section.

ApplicationModule am = null;
String amDef = &quot;test.TestModule&quot;;
String config = &quot;TestModuleLocal&quot;;
am = Configuration.createRootApplicationModule(amDef, config);
ViewObject vo = am.findViewObject(&quot;TestView&quot;);
// Work with your appmodule and view object here [Apply ViewCteria and execute VO]
finally {
if (null != am) {
Configuration.releaseRootApplicationModule(am, true);
am = null;
}
}

2.  Getting VO from Bindings programmatically and Applying VC on it: Simply create a java class and register it as a managed bean and then inside the method get the Iterator bindings [bindings should present in the page from which method is getting called] from which get VO then apply VC and execute. This is better method than previous method but still not much code efficient.


BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding itrBind = (DCIteratorBinding)bindings.get(&quot;EmployeesView1Iterator&quot;);
ViewObject empVO = itrBind.getViewObject();
empVO.clearCache();
ViewCriteriaManager vcm = empVO.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria(&quot;EmployeesViewCriteria&quot;);
empVO.applyViewCriteria(vc);
empVO.setNamedWhereClauseParam(&quot;DeptId&quot;, 100);
empVO.executeQuery();

 

3. Create a method in AppModuleImpl class in which apply VC on VO and execute it before calling the page using Taskflow:

Generate AppModuleImpl class and then create a method inside the class and once coding is done then go to Client Interface of AppModule and move the created method to the client interface, so that it is visible in the data controls section of the AppModule and can be used in Taskflow or can be used in JSPX page also.

public void applyVC(){
ViewObject empVO = this.getEmployeesView1();
ViewCriteriaManager vcm = empVO.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria(&quot;EmployeesViewCriteria&quot;);
empVO.applyViewCriteria(vc);
empVO.setNamedWhereClauseParam(&quot;DpetId&quot;, 100);
empVO.executeQuery();
}

Now all we need to do is execute the above method using Taskflow before the page is being called as we have to apply VC on VO and the results we have to display on the page.

 

 

 

af:table component structure in ADF

<af:table value="#{bindings.treename.collectionModel}"  var="row"
varStatus="vs">
<af:column headerText = "#{bindings.treename.hints.FirstName.label}"
sortable="true" filterable="true"
sortproperty = "#{bindings.treename.hints.FirstName.name}"
Editable tab- <af:inputText value = "#{row.bindings.FirstName.inputValue}" />
Readonly tab- <af:outputText value = "#{row.FirstName}" />
</af:column>

<af:column headerText = "#{bindings.treename.hints.departmentId.label}"
sortable="true" filterable="true"
sortproperty = #{bindings.treename.hints.departmentId.name}
<f:facet name="filter">
<af:inputDate value="#{vs.filterCriteria.HireDate}"/>
</f:facet>
Editable tab- <af:inputDate value="#{row.bindings.HireDate.inputValue}" />
Read only tab-  <af:outputText value="#{row.HireDate}" >
</af:column>

<af:column headerText = "#{bindings.treename.hints.departmentId.label}"
sortable="true" filterable="true"
sortproperty = #{bindings.treename.hints.departmentId.name}
<f:facet name="filter">
<af:selectOneChoice value="#{vs.filterCriteria.DepartmentId}"
inlineStyle="width:100px" autoSubmit="true">
<af:forEach items="#{bindings.DepartmentsView1.rangeSet}"
var="listRow">
<f:selectItem itemValue="#{listRow.DepartmentId}"
itemLabel="#{listRow.DepartmentName}"/>
</af:forEach>
</af:selectOneChoice>
</f:facet>
Editable tab- <af:inputText value="#{row.bindings.DepartmentId.inputValue}">
Read only tab- <af:outputText value="#{row.DepartmentId}">
</af:column>
</af:table>

 

Result: This code displayes the updatable/read only table. In the top input text as default filter for all columns and date or LOV or customized component for the columns which use <f:facet name =”filter” />. The default implementation of the table filter cell renderer is an af:inputText field.

Front end display will be like below:

table

Note: If you want to add a filter like we have done it here for Department Id column you need place the filter component in the filter facet of a column. Here we have added LOV filter (SelectOneChoice) and inside that we have placed foreach to which bindings we’ve given for DepartmentsVO . There is no need to be any relationship between employees and departments to create in adf. Just Department Id should present in both VOs that is enough. And your page should contain both the VOs tree bindings. No need to do any child relationship like that just drag two VOs datacontrols as tree bindings to the page.