Reputation: 57
<ViewObject name ="emp" selectList="select * from employees" Where= "empno=?" />
inside my action class, I'd like to change the where condition to sal=10
leading to select * from employees Where sal =10
.
I don't want the empno
column in the WHERE
clause.
the vo.setwhereclause(null)
isn't clearing the empno =?
. It's appending sal=?
to existing where clause.
How to solve this?
Upvotes: 1
Views: 8000
Reputation: 11
Dynamic clauses can only be appended to VO query. If there is a need to remove any clause from VO query, there is no method present for that, so the below code can be used as a workaround:
System.out.println("Original query: " +sanctVo.getQuery());
sanctVo.setQuery("select * from employees where sal = :1");
sanctVo.setWhereClauseParam(0, 10);
System.out.println("New query: " +sanctVo.getQuery());
sanctVo.executeQuery();
Upvotes: 0
Reputation: 99
A simplest way to do this is don't include where param in your view object query but use your where param dynamically through back bean or managed bean function code like,
ViewObject vo1 = applicationmoduleobject.findViewObject("viewobjectname");
vo.setWhereClause(" CREATED_BY = userId and ASSIGNMENT_ID = assignId");
long count = vo.getEstimatedRowCount();
Here, in your view object use simple "select * query" and dynamically add where clause using bean method and execute your view object.
Upvotes: 1
Reputation: 465
By default ViewObject augments where clause to existing sql code. To avoid this trouble you should use ViewObject.FULLSQL_MODE_AUGMENTATION property. Example:
ViewObject vo = getViewObject();
vo.setFullSqlMode(voi.FULLSQL_MODE_AUGMENTATION);
vo.setWhereClause("sal=:sal"); //or use setSql()
vo.setWhereClauseParam("sal",10.00);
vo.clearCache();
vo.executeQuery();
Upvotes: 0
Reputation: 8395
Maybe this will help you solve it:
<ViewObject name="emp" selectList="select * from employees" Where="sal=10" />
Upvotes: 0