cancel
Showing results for 
Search instead for 
Did you mean: 

Public Parts and Used DC's Struct. to implement Java Bean Model in WD4J

Former Member
0 Kudos

Hi,<br><br>

Iu2019m trying to implement a solution with Web Dynpro using Java Beans model, but Iu2019m facing a problem of how the projects depends one another, and maybe someone could help me.<br><br>

The application will be used to manage questionnaires, and the data will be stored on the Database. To simplify the explanation here, let assume that database only has a single table u201CQuestionnaireu201D.<br><br>

I created the following projects, public parts and used definitions:<br><br>

- Dictionary Project containing a single table u201CQuestionnaireu201D with following fields (ID, NAME, DESCRIPTION, FROM_DATE, TO_DATE);<br><br>

- Java Project containing 2 classes, and the entire package was made available as public part (Assembly and Compilation):<br><br>

o One class describes the table, that will be used by the Command Bean class and also by the EJB:<br><br>

<!-- CODE --><br>

public class Questionnaire implements Serializable{<br>

private short id;<br>

private String name;<br>

private String description;<br>

private Timestamp fromDate;<br>

private Timestamp toDate;<br><br>

//Respective methods Getter and Setter for all properties/variables above<br>

}<br>

<!-- CODE --><br>

o Command Bean Class, used as intermediary between Web Dynpro Application (Model) and EJB, because it needs to use the EJB class, included it as "Used DCu2019s" of the Java project:<br><br>

<!-- CODE --><br>

public class QuestionnaireCommandBean{<br>

private Collection questionnaireList = null;<br>

private Questionnaire questionnaire = null;<br>

private QuestionnaireBean session = null;<br><br>

public EspecialidadeDAO(){<br>

try{<br>

Context context = new InitialContext();<br>

QuestionnaireBeanHome home = (QuestionnaireBeanHome) context.lookup(JNDI_ESPECIALIDADE);<br>

session = home.create();<br>

}catch(Exception exception){}<br>

}<br><br>

public void getAllEspecialidades() throws RemoteException {<br>

Questionnaire helperClass[] = session.getAll();<br>

questionnaireList = new ArrayList();<br>

for(int i=0;i<helperClass.length;i++){<br>

questionnaireList.add(helperClass<i>);<br>

}<br>

}<br>

}<br>

<!-- CODE --><br><br>

- EJB Project containing one Stateless Session Bean u201CQuestionnaireBeanu201D, and this bean containing a single method u201CgetAllu201D with no input parameters and as an ouput an array of type class u201CQuestionnaireu201D<br><br>

<!-- CODE --><br>

public EspecialidadeDTO[] getAll() throws SQLException {<br>

u2026<br>

ds = (DataSource) context.lookup(DATASOURCE_ALIAS);<br>

con = ds.getConnection();<br>

u2026<br><br>

questionnaireArray = new Questionnaire[numOfRows];<br><br>

//Get Questionnaires<br>

pstm = con.prepareStatement("SELECT ID, NAME, DESCRIPTION,FROM_DATE, TO_DATE FROM Z_QUESTIONNAIRE");<br>

rSet = pstm.executeQuery();<br><br>

int i = 0;<br>

while (rSet.next()) {<br>

questionnaireArray <i> = new Questionnaire();<br>

questionnaireArray <i>.setId(rSet.getShort("ID"));<br>

questionnaireArray <i>.setNome(rSet.getString("NAME"));<br>

questionnaireArray <i>.setDescricao(rSet.getString("DESCRIPTION"));<br>

questionnaireArray <i>.setCreatedBy(rSet.getString("FROM_DATE"));<br>

questionnaireArray <i>.setModifiedBy(rSet.getString("TO_DATE"));<br>

i++;<br>

}<br><br>

return especialidadeArray;<br>

}<br><br>

Now comes the issue: Command Bean Class use DC EJB, and EJB Session Bean Project use DC Java Project (because it needs the Questionnaire class (Table definition) as return of the method getAll), with this project definitions, when building the EJB Project the message u201CFull build impossible due to cyclic DC usagesu201D is raised, which I fully understand, both projects are using each other. How should the projects be structured, to work?<br><br>

Note: Iu2019m developing in NW 7.0, so it is no possible to use EJB models like in CE, and I would like to not use Web Services model, as it adds a layer in the communication.<br><br>

Thanks & regards,<br>

John

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Move your java classes in separate DC. Your value objects (java classes) project must not use any other DCs, the other two DCs will use them.

1. Java classes (your Questionnaire class) are in different DC, they will not use anything.

2. DC EJB will use DC 1 - java classes.

3. DC that contains command bean class will use DCs 1 and 2.

I think this will solve your problem.

Former Member
0 Kudos

Hi Anton Dimitrov,

That was what I was afraid of, Iu2019ll try it, and will certainly work, but itu2019s unbelievable that to implement Java Bean Model, we need to create 5 projects:

1. DC Java Project for Questionnaire

2. DC Java Project for Command Bean

3. DC EJB Project for Session Bean

4. DC EAR Project

5. DC Web Dynpro Project

Thanks & Regards,

John

Answers (1)

Answers (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi John Travolta

Move class Questionnaire from EJB DC to Java DC. Remove EJB DC -> Java DC reference. This should solve the problem.

If EJB method returns list of Questionnaire it's quite logical that class Questionnaire shall belong to EJB DC as well.

BR, Siarhei

Former Member
0 Kudos

Hi Siarhei Pisarenka,

The class Questionnaire already makes part of JAVA DC Project and not from EJB DC, and cannot remove EJB DC -> Java DC Reference, because the method getAll from EJB returns an object of type Questionnaire.

Resuming, both Command Bean and EJB uses Questionnaire Class, and because Questionnaire Class makes part of same Java DC project as Command Bean, a Cycle Building error is shown.

Thanks & Regards,

John

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi John

Still I do not understand your situation clearly...

>The class Questionnaire already makes part of JAVA DC Project...

Why cannot you move Questionnaire to EJB DC? Any technical reasons?

Generic question: Why do you need the Command Bean at all if it just invokes the EJB without bringing any additional logic? Why cannot you import EJB model directly in the WebDynpro application instead of Java Bean model?

BR, Siarhei

Former Member
0 Kudos

Hi Siarhei Pisarenka,

I wouldnu2019t like to move it to EJB, for a coherence reason, of not mixing Helper Classes in EJB project.

AFAIK and as refered in help.sap.com, in NW 7.0 version is not possible to import EJB model directly into Web Dynpro Project, only using Java Beam Models (Command Bean pattern).

After separating Command Bean and Questionnaire Classes into two different projects, Iu2019m already able to build everything, now the problem is importing the Java Bean Model, after adding JAVA DC Project (Command Bean) as Used DC into Web Dynpro Project, when creating the Model and selecting from Public Part, no jar file is shown in the list.

Thanks & Regards,

John